<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        //工厂方法创建对象，利用字面量创建
        // 1    function button(weight, height, backcolor) {
        //         let obj = new Object();
        //         obj.weight = weight;
        //         obj.height = height;
        //         obj.backcolor = backcolor;
        //         obj.link = function () {
        //             console.log('点击');
        //         }
        //         return obj;
        //     }
        //     let button1 = button(20, 30, 'red');
        //     console.log(button1);
        //  
        //     button1.link();
        //2
        function button(weight, height, backcolor) {
            this.weight = weight;
            this.height = height;
            this.backcolor = backcolor;
            this.link = function () {
                console.log('点击');
            }
        }
        let button1 = new button(20, 30, 'red');
        console.log(button1);
        button1.link();




        //1 function creatCar(weight, color, logo) {
        //     let obj = new Object;
        //     obj.weight = weight;
        //     obj.color = color;
        //     obj.logo = logo;
        //     obj.zairen = function () {
        //         console.log('载人');
        //     }
        //     obj.lahuo = function () {
        //         console.log('拉货');
        //     }
        //     obj.gengtian = function () {
        //         console.log('耕田');
        //     }
        //     return obj;
        // }
        // let car1 = creatCar('1t', 'red', '奔驰');
        // console.log(car1);
        // car1.zairen();
        // car1.gengtian();
        // car1.lahuo();


        //2构建函数创建对象
        function Car(weight, color, logo) {
            this.weight = weight;
            this.color = color;
            this.logo = logo;
            this.zairen = function () {
                console.log('载人');
            }
            this.lahuo = function () {
                console.log('拉货');
            }
            this.gengtian = function () {
                console.log('耕田');
            }

        }
        let car1 = new Car('1t', 'red', '奔驰');
        console.log(car1);
        car1.zairen();
        car1.lahuo();
        car1.gengtian();
    </script>
</head>

<body>

</body>

</html>